import { Tabs, Form } from 'antd';
import { connect } from 'dva';
import CreateTitle from './components/createTitle';
import CreateParagraph from './components/createParagraph';
import AutoGenerate from './components/autoGenerate';
const { TabPane } = Tabs;
const creator = (type, payload) => ({ type, payload });

const Create = props => {
  function callback(key) {
    const { dispatch } = props;
    if (key === '1' || key === '2') {
      dispatch(creator('title/getTitles'));
    } else {
      dispatch(creator('paragraph/getParagraphs'));
    }
  }

  return (
    <Tabs defaultActiveKey="1" onChange={callback}>
      <TabPane tab="后台自动创建" key="1">
        <AutoGenerate />
      </TabPane>
      <TabPane tab="创建文章标题" key="2">
        <CreateTitle />
      </TabPane>
      <TabPane tab="创建文章段落" key="3">
        <CreateParagraph />
      </TabPane>
    </Tabs>
  );
};

export default connect(({ title, paragraph }) => ({ title, paragraph }))(Create);
